package cn.droidlover.mywegit;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import cn.droidlover.mywegit.util.Weather;

public class WeatherView extends RelativeLayout {

    TextView mtv_adr,mtv_data1,mtv_data2,mtv_data3,mtv_temp1,mtv_temp2,mtv_temp3,mtv_weather1,mtv_weather2,mtv_weather3;


    ImageView mimage_1,mimage_2,mimage_3;

    public WeatherView(Context context, AttributeSet attrs) {
        super(context,attrs);

        LayoutInflater.from(context).inflate(R.layout.layout_weather, this);

        mtv_adr=findViewById(R.id.tv_adr);
        mtv_data1=findViewById(R.id.tv_date1);
        mtv_data2=findViewById(R.id.tv_date2);
        mtv_data3=findViewById(R.id.tv_date3);
        mtv_temp1=findViewById(R.id.tv_temp1);
        mtv_temp2=findViewById(R.id.tv_temp2);
        mtv_temp3=findViewById(R.id.tv_temp3);

        mtv_weather1=findViewById(R.id.tv_weather1);
        mtv_weather2=findViewById(R.id.tv_weather2);
        mtv_weather3=findViewById(R.id.tv_weather3);

        mimage_1=findViewById(R.id.image_1);
        mimage_2=findViewById(R.id.image_2);
        mimage_3=findViewById(R.id.image_3);


    }


    public void setData(Weather weather)
    {
        this.mtv_adr.setText(weather.getCity().getValue());
        this.mtv_data1.setText("今天("+weather.getData1().getValue().get(0).getDate().getValue().substring(5)+")");
        this.mtv_data2.setText("明天("+weather.getData1().getValue().get(1).getDate().getValue().substring(5)+")");
        this.mtv_data3.setText("后天("+weather.getData1().getValue().get(2).getDate().getValue().substring(5)+")");

        this.mtv_temp1.setText(weather.getData1().getValue().get(0).getTemp().getValue());
        this.mtv_temp2.setText(weather.getData1().getValue().get(1).getTemp().getValue());
        this.mtv_temp3.setText(weather.getData1().getValue().get(2).getTemp().getValue());

        this.mtv_weather1.setText(weather.getData1().getValue().get(0).getWeather().getValue());
        this.mtv_weather2.setText(weather.getData1().getValue().get(1).getWeather().getValue());
        this.mtv_weather3.setText(weather.getData1().getValue().get(2).getWeather().getValue());

        Glide.with(getContext()).load(weather.getData1().getValue().get(0).getWeather_pic().getValue()).into(mimage_1);
        Glide.with(getContext()).load(weather.getData1().getValue().get(1).getWeather_pic().getValue()).into(mimage_2);
        Glide.with(getContext()).load(weather.getData1().getValue().get(2).getWeather_pic().getValue()).into(mimage_3);

    }



}
